package com.ihg.hiex.admin.entity.search;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.ihg.hiex.entity.user.Role;

/**
 *
 * @author Ark
 *
 */
public class AdministratorSearch implements QueryBuilder {

    private String name;
    
    private String email;
    
    private String location;
    
    private QueryFilter queryFilter;
    
    private QueryOrder queryOrder;
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {
        	
            queryFilter = new QueryFilter();
            
            queryFilter.addEquals("email", email)
                       .addEquals("role", Role.ADMIN.toString())
            		   .addLike("name", name)
            		   .addLike("location", location);
            
        }
        
        return queryFilter;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        if (queryOrder == null) {
            queryOrder = new QueryOrder("lastModifyTime", "DESC");
        }
        return queryOrder;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM Administrator WHERE disabled = false " + getPreparedFilter(false).clauseSentence();
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }

	/**
	 * @return the queryFilter
	 */
	public QueryFilter getQueryFilter() {
		return this.queryFilter;
	}

	/**
	 * @return the queryOrder
	 */
	public QueryOrder getQueryOrder() {
		return this.queryOrder;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return this.email;
	}

	/**
	 * @return the location
	 */
	public String getLocation() {
		return this.location;
	}

	/**
	 * @param queryFilter the queryFilter to set
	 */
	public void setQueryFilter(QueryFilter queryFilter) {
		this.queryFilter = queryFilter;
	}

	/**
	 * @param queryOrder the queryOrder to set
	 */
	public void setQueryOrder(QueryOrder queryOrder) {
		this.queryOrder = queryOrder;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @param location the location to set
	 */
	public void setLocation(String location) {
		this.location = location;
	}
    
}